23 template <class T
> string
toStr(const T
&x
){ stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
){ stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define D(x) cout << #x " is " << x << endl
30 typedef unsigned long long Int
;
31 const int BUFSIZE
= 128;
40 node(bool e
) : end(e
) {
46 if (n
== NULL
) return;
47 clean(n
->left
); clean(n
->right
);
52 Int
f(string s
, node
* n
){
53 Int left
= 0, right
= 0;
55 left
= f(s
+ "0", n
->left
);
57 if (n
->right
!= NULL
){
58 right
= f(s
+ "1", n
->right
);
61 Int x
= ((1ULL) << (M
- s
.size())) - 1;
62 if (M
== 64 && s
.size() == 0){
65 ans
[s
] = x
- left
- right
+ 1;
73 return ret
+ left
+ right
;
78 while (cin
>> n
>> M
&& !(n
== 0 && M
== 0)){
80 node
* root
= new node(true);
91 if (cur
->left
== NULL
) cur
->left
= new node(false);
94 if (cur
->right
== NULL
) cur
->right
= new node(false);
107 buf
.resize(buf
.size()-1);